import { Tooltip } from "ant-design-vue";
import dayjs from "dayjs";
import type { ActionProps, CommonSearchFile } from "~/types/enum";
import { $t } from "@/locales";

export enum ControllerApi {
  GetList = "api/Log/GetListb",
  Export = "/api/Log/ExportDatab"
}
export class ControllerAction {
  actionPros: ActionProps = {
    addCode: "",
    deleteCode: "",
    updateCode: "",
    queryCode: "ControllerlogGetList",
    importCode: "",
    exportCode: "ControllerlogExport",
    downImportCode: "",
    reductionCode: "",
    recyclebinCode: ""
  };
}
export interface ControllerInfo {
  Id: string;
  requestmode: string;
  ipaddress: string;
  name: string;
  method?: string;
  hearddata?: string;
  parameterdata?: string;
  backresult?: string;
  ucode?: string;
  status?: string;
  Remark?: string;
  cTime?: Date;
  uTime?: Date;
}

export const displayColumns = (): any => {
  return [
    {
      key: "index",
      title: $t("common.index"),
      dataIndex: "index",
      align: "center",
      width: 64
    },
    {
      key: "ucode",
      dataIndex: "ucode",
      title: "操作账号",
      align: "center",
      width: 160
    },
    {
      key: "cTime",
      dataIndex: "cTime",
      title: "操作时间",
      align: "center",
      width: 140
    },
    {
      key: "ipaddress",
      dataIndex: "ipaddress",
      title: "IP地址",
      align: "center",
      width: 140
    },
    {
      key: "name",
      dataIndex: "name",
      title: "控制器名称",
      align: "center",
      width: 140
    },
    {
      key: "method",
      dataIndex: "method",
      title: "控制器方法",
      align: "center",
      width: 140
    },
    {
      key: "requestmode",
      dataIndex: "requestmode",
      title: "请求方式",
      align: "center",
      width: 140
    },
    {
      key: "parameterdata",
      dataIndex: "parameterdata",
      align: "center",
      title: "控制器参数",
      width: 260,
      ellipsis: {
        showTitle: false
      },
      customRender(opt: any) {
        return (
          <Tooltip placement="topLeft" title={opt.text}>
            <span style="cursor: pointer;">{opt.text}</span>
          </Tooltip>
        );
      }
    },
    {
      key: "hearddata",
      dataIndex: "hearddata",
      align: "center",
      title: "请求头信息",
      width: 260,
      ellipsis: {
        showTitle: false
      },
      customRender(opt: any) {
        return (
          <Tooltip placement="topLeft" title={opt.text}>
            <span style="cursor: pointer;">{opt.text}</span>
          </Tooltip>
        );
      }
    }
  ];
};

export const apiParams = (): any => {
  return {
    sortFile: "Id",
    sortType: "desc",
    files: "*",
    pageIndex: 1,
    pageSize: 20,
    ucode: "",
    ipaddress: "",
    name: "",
    method: "",
    requestmode: "",
    status: "-1",
    stime: dayjs(dayjs(new Date()).format("YYYY-MM-DD 00:00:00")),
    etime: dayjs(dayjs(new Date()).format("YYYY-MM-DD 23:59:59")),
    sttime: dayjs(new Date()).format("YYYY-MM-DD 00:00:00"),
    ettime: dayjs(new Date()).format("YYYY-MM-DD 23:59:59")
  };
};

export const searchForm = (): CommonSearchFile[] => {
  return [
    {
      span: 24,
      md: 12,
      lg: 3,
      name: "ucode",
      placeholder: "操作账号",
      allowClear: false,
      type: "input"
    },
    {
      span: 24,
      md: 12,
      lg: 3,
      name: "ipaddress",
      placeholder: "IP地址",
      allowClear: false,
      type: "input"
    },
    {
      span: 24,
      md: 12,
      lg: 3,
      name: "name",
      placeholder: "控制器名称",
      allowClear: false,
      type: "input"
    },
    {
      span: 24,
      md: 12,
      lg: 3,
      name: "method",
      placeholder: "控制器方法",
      allowClear: false,
      type: "input"
    },
    {
      span: 24,
      md: 12,
      lg: 3,
      name: "requestmode",
      placeholder: "请求方式",
      allowClear: false,
      type: "input"
    }
  ];
};
